<?php
defined("BASEDIR") or die();
 
 class Application_Controller_Events extends Application_Controller_Default
 {
     
     #public $x;
	public function defaultAction()
	{
		$user = Application_Router_Standard_User::getInstance($this->request);
		if($user->level < $this->modInfo['requiredLevel'])
		{
			$this->request->action = "notallowed";
			return;
		}
		else 
                {
			$this->request->action = $this->request->controller;

                        $db = Application_Model_DataBase::getInstance();
                        $ses = Application_Model_SessionControl::getInstance();
                        $username=$ses->un;
                        #print($username);
                        #$ip = (empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR']);
                        
                        $db->getTable("Zapisy");
                        $db->setFields("zid");

                        $db->where("pesel='".$username."'");
                        $num = $db->execute();
                        
                      #  while ($qres = $db->getResult());
                      #  {
                        $zid[]=$qres["zid"];
                        #print($zid);

                        #$db = Application_Model_DataBase::getInstance();
                        $db->getTable("Zabiegi");
                        
                        $db->where("zid='".$zid."'");
                        $num1 = $db->execute();
                        $qres1 = $db->getResult();
                        $start =$qres1["start"];
                        $koniec=$qres1["koniec"];
                        $data=$qres1["data"];
                        $pid=$qres1["pid"];
                        $tid=$qres1["tid"];
                        $db->getTable("Typy_zabiegow");
                        $db->where("tid='".$tid."'");
                        $num2 = $db->execute();
                        $qres2 = $db->getResult();
                        $typ=$qres2["typ"];
                        $db->query("SELECT zid from Zapisy where pesel = $username");


#print($typ);
                        #
                        #
                        #print($start);
                        #print($stop);
                        #print($data);
                        #}
                        $this->view->assign("typ", $typ); # nazwa zabiegu
                        $this->view->assign("start", $start); #start godzina
                        $this->view->assign("koniec", $koniec); #stop godzina
                        $this->view->assign("data", $data);# data zabiegu

                        
                        }
                }
				
				public function jsonAction() {
				$db = Application_Model_DataBase::getInstance();
                            $ses = Application_Model_SessionControl::getInstance();
                            $username=$ses->un;
                            $username="11111";
                            $db->query("SELECT zid from Zapisy where pesel = '".$username."'");
                            $num = $db->execute();
                           # print($num);
                           # print($qres = $db->getResult());
						   $xxxx=0;
						   print '[';
                            while($qres = $db->getResult())
                            {
							$xxxx++;
							if ($xxxx!=1) print",";
                                $zid=$qres["zid"];
                                //print_r($zid);
                                $db->query("SELECT tid from Zabiegi where zid = '".$zid."'");
                                $num = $db->execute();
                                $qres = $db->getResult();
                                 $tid=$qres["tid"];
                                #print_r($qres);
                                 $db->query("SELECT start from Zabiegi where zid = '".$zid."'");
                                $num = $db->execute();
                                $qres = $db->getResult();
                                $start=$qres["start"];
                                $db->query("SELECT koniec from Zabiegi where zid = '".$zid."'");
                                $num = $db->execute();
                                $qres = $db->getResult();
                                $koniec=$qres["koniec"];
                                $db->query("SELECT data from Zabiegi where zid = '".$zid."'");
                                $num = $db->execute();
                                $qres = $db->getResult();
                                $data=$qres["data"];
                                $db->query("SELECT typ from Typy_zabiegow where tid = '".$tid."'");
                                $num = $db->execute();
                                $qres = $db->getResult();
                                $typ=$qres["typ"];
                                //print($start);
								
                                print'{"title":"'.$typ.'","start":"'.$data.'T'.$start.'-01:00","end":"'.$data.'T'.$koniec.'-01:00"}';
							
                            }
							print "]";
				}
        }
 
 
 